package Z008NumberAndString.NS11Date;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class CalendarDemo {}

// Calendar与Date进行转换
class TestCalendar{
    public static void main(String[] args) {
        // 采用单例模式获得日历对象Calendar.getInstance()
        Calendar c = Calendar.getInstance();
        // 通过日历对象得到日期对象
        Date d = c.getTime();
        Date d2 = new Date(0);
        c.setTime(d2);
        // 调整这个日历，格式为：1970.1.1 00:00:00
    }
}

class TestCalendar1{
    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:ss:ss");


    public static void main(String[] args) {
        Calendar c = Calendar.getInstance();
        Date now = c.getTime();
        System.out.println("当前日期：\t"+sdf.format(c.getTime()));


        c.setTime(now);
        c.add(Calendar.MONTH,1);
        System.out.println("下个月的今天：\t" + sdf.format(c.getTime()));

        c.setTime(now);
        c.add(Calendar.YEAR,-1);
        System.out.println("去年的今天：\t" + sdf.format(c.getTime()));

        c.setTime(now);
        c.add(Calendar.MONTH,-1);
        c.set(Calendar.DATE,3);
        System.out.println("上个月的第三天：\t" + sdf.format(c.getTime()));

    }
}